{% from 'include/input_macros.html' import input, select, checkbox %}
{% from 'include/provisioning/variables.html' import aws_regions, aws_oss, aws_volume_type  %}
{% for s in server %}
{% set region_name = [] %}
<div id="aws_edit" style="display: none; padding: 0 2px 0 0; margin-left: 1px; margin-right: -4px;">
    <table class="overview provisioning_table">
        {% include 'include/tr_validate_tips.html' %}
        <tr>
            <td colspan="2" class="headers">
                <b>General information</b>
            </td>
        </tr>
        <tr>
            <td class="padding20">
                Server name
            </td>
            <td>
                <span id="aws_edit_server_name">{{s.name}}</span>
            </td>
        </tr>
            {{input('aws_edit_group', value=s.group_id, type='hidden')}}
            {{input('aws_edit_id', value=s.id, type='hidden')}}
        <tr>
            <td class="padding20">
                Provider credentials
                <span class="need-field">*</span>
            </td>
            <td>
                <select id="aws_edit_id_provider">
                {% for p in providers %}
                    {% if p.2 == 'aws' %}
                        {% if s.provider_id|int() == p.0|int() %}
                        <option value="{{ p.0 }}" selected>{{ p.1 }}</option>
                        {% else %}
                        <option value="{{ p.0 }}">{{ p.1 }}</option>
                        {% endif %}
                    {% endif %}
                {% endfor %}
                </select>
            </td>
        </tr>
        <tr>
            <td class="padding20">
                Region
            </td>
            <td>
                {% for key, value in aws_regions.items() %}
                {% if s.region|int() == key|int() %}
                    {% do region_name.append(value) %}
                {% endif %}
                {% endfor %}
                <span id="aws_edit_region" style="display: none;">{{s.region}}</span>
                {{region_name.0}}
            </td>
        </tr>
        <tr>
            <td colspan="2" class="headers">
                <b>Instance</b>
            </td>
        </tr>
        <tr>
            <td class="padding20 padding-top20">
                Instance type
                <span class="need-field">*</span>
            </td>
            <td>
                {{input('aws_edit_size', size='26', value=s.instance_type)}}
                <div class="tooltip tooltipTop tooltipTd">
                    Instance types list is <a href="https://aws.amazon.com/ec2/instance-types/" title="Instance types list" target="_blank">here</a>
                </div>
            </td>
        </tr>
        <tr>
            <td class="padding20">
                OS
                <span class="need-field">*</span>
            </td>
            <td>
                {{ select('aws_edit_oss', values=aws_oss, first=s.os, disabled='false') }}
            </td>
        </tr>
        <tr>
            <td class="padding20 padding-top20">
                SSH key pair name
                <span class="need-field">*</span>
            </td>
            <td>
                {{input('aws_edit_ssh_name', size='26', value=s.ssh_key_name)}}
                <div class="tooltip tooltipTop tooltipTd">SSH key must exists in region where instance create</div>
            </td>
        </tr>
        <tr>
            <td colspan="2" class="headers">
                <b>Volume</b>
            </td>
        </tr>
        <tr>
            <td class="padding20">
                Volume size
                <span class="need-field">*</span>
            </td>
            <td>
                {{input('aws_edit_volume_size', size='26', value=s.volume_size, type='number')}}Gb
            </td>
        </tr>
        <tr>
            <td class="padding20">
                Volume type
                <span class="need-field">*</span>
            </td>
            <td>
                <select id="aws_edit_volume_type">
                    {% for key, value in aws_volume_type.items() %}
                        {% if s.volume_type == key %}
                            <option value="{{key}}" selected>{{value}}</option>
                        {% else %}
                            <option value="{{key}}">{{value}}</option>
                        {% endif %}
                    {% endfor %}
                </select>
            </td>
        </tr>
        <tr>
            <td class="padding20 padding-top20">Delete on termination</td>
            <td>
                {% set checked='checked' %}
                {% if s.delete_on_termination == 'false' %}
                    {% set checked='' %}
                {% endif %}
                {{checkbox('aws_edit_delete_on_termination', checked=checked)}}
                <div class="tooltip tooltipTop tooltipTd">Whether the volume should be destroyed on instance termination</div>
            </td>
        </tr>
        <tr>
            <td colspan="2" class="headers">
                <b>Network</b>
            </td>
        </tr>
        <tr>
            <td class="padding20">Public IP</td>
            <td>
                <select id="aws_edit_public_ip">
                    {% if s.public_ip == 'true' %}
                    <option value="public" selected>Public IP</option>
                    {% else %}
                    <option value="public">Public IP</option>
                    {% endif %}
                    {% if s.floating_ip == 'true' %}
                    <option value="elastic" selected>Elastic IP</option>
                    {% else %}
                    <option value="elastic">Elastic IP</option>
                    {% endif %}
                    {% if s.public_ip == 'false' and s.floating_ip == 'false' %}
                    <option value="none" selected>None</option>
                    {% else %}
                    <option value="none">None</option>
                    {% endif %}
                </select>
            </td>
        </tr>
        <tr>
            {% set checked='checked' %}
            {% if s.firewall == 'false' %}
                {% set checked='' %}
            {% endif %}
            <td class="padding20" style="padding-bottom: 25px;padding-top: 25px;">Firewall</td>
            <td>
                {{checkbox('aws_edit_firewall', checked=checked)}}
                <div class="tooltip tooltipTop tooltipTd">Roxy-WI will create Security group and open 22, 443, 1999, 8085, 8086 ports. Otherwise all ports will be closed</div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <p class="validateTips alert alert-warning">Be aware: some changes may cause server re-creation. And all your data will be lost</p>
            </td>
        </tr>
    </table>
</div>
{% endfor %}